package com.hspedu.newData.剑指offer;

import org.junit.Test;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-05-04 
 * @Version: 1.0
 */

public class LCR189设计机械累加器 {

    // todo 不能使用条件判断语句，需要考虑结束递归的情况
    public int mechanicalAccumulator(int target) {
        if (target == 1){
            return 1;
        }
        return mechanicalAccumulator(target-1) + target;
    }

    @Test
    public void test() {
        // 测试代码
        int i = mechanicalAccumulator(5);
        int i1 = mechanicalAccumulator(7);
        System.out.println("0000000");
    }
}
